<?php
namespace Home\Controller;

use Think\Controller;
use Think\Page;

class ArticleController extends Controller  {

	public function index() {
		$ArticleModel = M('article');
		$count = $ArticleModel->count();
		$page = new Page($count);
		
		$articles = $ArticleModel->field(array('id', 'title', 'article_desc', 'img_path', 'created'))->where(array(
			'status' => 1,
		))->order('id DESC')->select();
		
		$hasMore = false;
		$pageNow = I('get.p')?I('get.p'):1;
		if ($page->totalPages > $pageNow) {
			$hasMore = true;
		}
		
		$this->assign("lists", $articles);
		$this->assign("hasMore", $hasMore);
		$this->display();
	}
	
	public function detail() {
		$id = I('get.id');
		
		if (!$id) {
			$this->error('资讯速递编号错误', U('Article/index'));
		}
		
// 		$wxUtil = new WxBaseInterface_util();
// 		$wxConfig = $wxUtil->getSignPackage();
		
// 		$smarty->assign('appId', WxConf::APPID);
// 		$smarty->assign('nonceStr', $wxConfig['nonceStr']);
// 		$smarty->assign('timestamp', $wxConfig['timestamp']);
// 		$smarty->assign('signature', $wxConfig['signature']);
		
		$ArticleModel = D('Article');
		$info = $ArticleModel->getArticleInfo($id);
		
		$info ['title'] = htmlspecialchars_decode($info ['title']);
		$info ['article_desc'] = htmlspecialchars_decode($info ['article_desc']);
		$info ['content'] = htmlspecialchars_decode($info ['content']);
		$info ['view'] += 1;
		
		$this->assign('share_title', $info ['title']);
		$this->assign('share_content', $info ['article_desc']);
		$this->assign('share_url', get_url().'/action/zixun.php?a=detail&id='.$zixun_id);
		$this->assign('share_picture', get_url().'/Uploads/Article/'.$info ['img_path']);
		
		$this->assign('zixun', $info);
		$this->display();
	}
}